package com.hspedu.exception_.try_.try_catchExercise;

/**
 * @Author Stringzhua
 * @Date 2024/3/8 10:43
 * description:
 */
public class TryCatchExercise02 {
    public static void main(String[] args) {
        System.out.println(method());
    }


    public static int method() {
        int i = 1;
        try {
            i++;
            String[] names = new String[3];
            if (names[1].equals("tom")) {//NullPointerException
                System.out.println(names[1]);
            } else {
                names[3] = "爪爪吃蒸饺";
            }
            return 1;
        } catch (ArrayIndexOutOfBoundsException e) {
            return 2;
        } catch (NullPointerException e) {
            return ++i;//++i=3
        } finally {
            return ++i;//i=4 覆盖了catch的return ++i
        }
    }
}
